﻿#ifndef __HTTPLIB_H__  
#define __HTTPLIB_H__
#include <string>
#include <map>
#include <functional>
#include "httpproxy.h"

namespace Network {
	// 封装底层的htpp
	class HttpRequest
	{
	public:
		// 如果对外提供接口是需要包含的到头文件中去
		using QueryHeader = std::map<std::string, std::string>;
		enum class ScheamType
		{
			Scheam_http = 0,
			Scheam_https = 1
		};

		struct RequestHeader
		{
			std::string _requestMethoad;
			std::string _url;
			std::string _path;
			std::string _httpVersion = "HTTP/1.1";
			std::string _host;
			std::string _port = "80";
			std::string _connection;
			std::string _domain;
			ScheamType _scheamType = ScheamType::Scheam_http;
			QueryHeader _queryHead;
			QueryHeader _defaultHead;
		};

		struct RequestSRT
		{
			RequestHeader _header;
			std::string _body;
			std::string toString();
		};


	public:
		HttpRequest(const std::string& url, RequestMethoad methoad, const QueryParams& params = QueryParams());
		virtual ~HttpRequest();
		void run();

	private:
		void init(const std::string& url, RequestMethoad methoad, const QueryParams& params);
		void parseScheam(const std::string& url, RequestSRT& reqSt);
		void parseDomainAndPath(const std::string& url, RequestSRT& reqSt);
		void parseHost(const std::string domain, RequestSRT& reqSt);
		void initDefaultHeaders(RequestSRT& reqSt);
		void initBody(const QueryParams& params, RequestSRT& reqSt);
	private:
		RequestSRT _requestSt;
	};
}
#endif // ! 
